﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace safehomeSimulation
{
    public partial class frmRoomConfigure : Form
    {
        private Room _roomCon;

        public frmRoomConfigure()
        {
            InitializeComponent();
        }

        public frmRoomConfigure(ref Room room)
        {
            _roomCon = room;
            InitializeComponent();
            if (_roomCon.HasCSensor)
                txtCOSensor.Enabled = true;
            if (_roomCon.HasSSensor)
                txtSSensor.Enabled = true;
            if (_roomCon.HasTSensor)
                txtTSensor.Enabled = true;
            if (_roomCon.HasWSensor)
                txtWSensor.Enabled = true;

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (_roomCon.HasCSensor)
                _roomCon.ConfigureCO(float.Parse(txtCOSensor.Text.ToString()));
            if (_roomCon.HasSSensor)
                _roomCon.ConfigureS(float.Parse(txtSSensor.Text.ToString()));
            if (_roomCon.HasTSensor)
                _roomCon.ConfigureT(float.Parse(txtTSensor.Text.ToString()));
            if (_roomCon.HasWSensor)
                _roomCon.ConfigureW(float.Parse(txtWSensor.Text.ToString()));

            this.Close();
        }

        private void txtTSensor_Validating(object sender, CancelEventArgs e)
        {
            if (this.Text.ToString() == string.Empty)
                this.Focus();

        }

        private void txtSSensor_Validating(object sender, CancelEventArgs e)
        {
            if (this.Text.ToString() == string.Empty)
                this.Focus();
        }

        private void txtWSensor_Validating(object sender, CancelEventArgs e)
        {
            if (this.Text.ToString() == string.Empty)
                this.Focus();
        }

        private void txtCOSensor_Validating(object sender, CancelEventArgs e)
        {
            if (this.Text.ToString() == string.Empty)
                this.Focus();
        }


    }
}
